package com.quan.upms.rpc.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import tk.mybatis.mapper.entity.Condition;

import com.quan.base.common.base.service.support.BaseService;
import com.quan.base.common.exception.BizException;
import com.quan.upms.rpc.api.UpmsGroupService;
import com.quan.upms.rpc.dao.mapper.UpmsGroupMapper;
import com.quan.upms.rpc.dao.mapper.UpmsUserGroupAssignMapper;
import com.quan.upms.rpc.model.UpmsGroup;
import com.quan.upms.rpc.model.UpmsUserGroupAssign;

@Service
public class UpmsGroupServiceImpl extends BaseService<UpmsGroup, Integer> implements UpmsGroupService {
	
	@Autowired
	private UpmsGroupMapper mapper ;

	@Autowired
	private UpmsUserGroupAssignMapper userGroupAssignMapper ;
	
	@Override
	public int delete(Integer id) throws BizException {
		//删除该组下的用户的关联关系
		Condition condition = new Condition(UpmsUserGroupAssign.class) ;
		condition.createCriteria().andEqualTo("groupId", id);
		this.userGroupAssignMapper.deleteByCondition(condition) ;
		return super.delete(id);
	}
	
	@Override
	public int deleteByIds(String ids) throws BizException {
		String[] split = ids.split(",");
		for (String id : split) {
			//删除该组下的用户的关联关系
			Condition condition = new Condition(UpmsUserGroupAssign.class) ;
			condition.createCriteria().andEqualTo("groupId", id);
			this.userGroupAssignMapper.deleteByCondition(condition) ;
		}
		return super.deleteByIds(ids);
	}
	
	
	@Override
	public void removeGroupUsers(String groupAssingIds) {
		this.userGroupAssignMapper.deleteByIds(groupAssingIds) ;
	}

}
